.panel-group
  - if can_manage_namespace?(@namespace)
    .collapse id="update_webhook_#{@webhook.id}"
      = form_for [@namespace, @webhook], remote: true, html: {class: 'form-horizontal', role: 'form'} do |f|
        .panel.panel-default
          .panel-heading
            .input-group
              = f.text_field(:url, class: 'form-control', required: true, placeholder: html_escape(@webhook.url), input_html: { tabindex: 1 })
              .input-group-btn
                button.btn.btn-link.btn-xs.btn-edit-webhook[
                  value="#{@webhook.id}"
                  type="button"
                  class="button_edit_webhook"]
                  i.fa.fa-close
                  | Edit webhook
          .panel-body
            .form-group
              = f.label :request_method, {class: 'control-label col-md-2'}
              .col-md-7
                = f.select(:request_method, Webhook.request_methods.keys, {}, {class: 'form-control'})
            .form-group
              = f.label :content_type, {class: 'control-label col-md-2'}
              .col-md-7
                = f.select(:content_type, Webhook.content_types.keys, {}, {class: 'form-control'})
            .form-group
              = f.label :username, {class: 'control-label col-md-2'}
              .col-md-7
                = f.text_field(:username, class: 'form-control', required: false, placeholder: "Username for authentication")
            .form-group
              = f.label :password, {class: 'control-label col-md-2'}
              .col-md-7
                = f.password_field(:password, class: 'form-control', required: false, placeholder: "Password for authentication")
            .form-group
              .col-md-offset-2.col-md-7
                = f.submit('Save', class: 'btn btn-primary')
            .errors

  .panel.panel-default.webhook_information
    .panel-heading
      h5
        strong
          '#{@webhook.host}
        ' webhook
        small
          a[data-placement="right" data-toggle="popover" data-container=".panel-heading" data-content="<b>Request method</b>: URL endpoint where the HTTP request is sent to.<br/><b>Content type</b>: Description of the webhook request content.<br/><b>Username</b>: Username used for basic HTTP auth.<br/><b>Password</b>: Password used for basic HTTP auth." data-original-title="What's this?" tabindex="0" data-html="true"]
            i.fa.fa-info-circle
        - if can_manage_namespace?(@namespace)
          .pull-right
            button.btn.btn-link.btn-xs.btn-edit-webhook[
              value="#{@webhook.id}"
              class="button_edit_webhook"]
              i.fa.fa-pencil
              | Edit webhook
    .panel-body
      = render partial: "detail", locals: {webhook: @webhook}

- if can_manage_namespace?(@namespace)
  #add_webhook_header_form.collapse
    = form_for :webhook_header, url: namespace_webhook_headers_path(@namespace, @webhook), remote: true, html: {id: 'new-header-form', class: 'form-horizontal', role: 'form'} do |f|
      .form-group
        = f.label :name, {class: 'control-label col-md-2'}
        .col-md-7
          = f.text_field(:name, class: 'form-control', required: true, placeholder: "Name")
      .form-group
        = f.label :value, {class: 'control-label col-md-2'}
        .col-md-7
          = f.text_field(:value, class: 'form-control', required: true, placeholder: "Value")
      .form-group
        .col-md-offset-2.col-md-7
          = f.submit('Create', class: 'btn btn-primary')
      .errors

.panel.panel-default
  .panel-heading
    h5
      ' Headers
      small
        a[data-placement="right" data-toggle="popover" data-container=".panel-heading" data-content="A header is a HTTP header, i.e. is a key-value pair which is included in the HTTP request." data-original-title="What's this?" tabindex="0"]
          i.fa.fa-info-circle
      - if can_manage_namespace?(@namespace)
        .pull-right
          a#add_webhook_header_btn.btn.btn-xs.btn-link.js-toggle-button[role="button"]
            i.fa.fa-plus-circle
            | Create new header
  .panel-body
    .table-responsive
      table.table.table-stripped.table-hover
        colgroup
            col.col-20
            - if can_manage_namespace?(@namespace)
              col.col-70
              col.col-10
            - else
              col.col-80
        thead
          tr
            th Name
            th Value
            - if can_manage_namespace?(@namespace)
              th Remove
        tbody#webhook_headers
          - @webhook.headers.each do |header|
            = render partial: 'webhook_headers/webhook_header', locals: {namespace: @namespace, webhook: @webhook, webhook_header: header}

.panel.panel-default
  .panel-heading
    h5
      ' Deliveries
      small
        a[data-placement="right" data-toggle="popover" data-container=".panel-heading" data-content="A delivery is created once a webhook has been triggered. They are not re-created but updated after retriggering." data-original-title="What's this?" tabindex="0"]
          i.fa.fa-info-circle
  .panel-body
    .table-responsive
      table.table.table-stripped.table-hover
        colgroup
            - if can_manage_namespace?(@namespace)
              col.col-90
              col.col-10
            - else
              col.col-100
        thead
          tr
            th UUID
            - if can_manage_namespace?(@namespace)
              th Retrigger
        tbody#webhook_deliveries
          - @deliveries.each do |delivery|
            tr[id="webhook_delivery_#{delivery.id}"]
              td
                - if delivery.success?
                  i.fa.fa-check.fa-lg.text-success
                - else
                  i.fa.fa-close.fa-lg.text-danger
                = delivery.uuid
              - if can_manage_namespace?(@namespace)
                td
                  - if delivery.webhook.enabled
                    a.btn.btn-default.btn-retrigger-webhook[data-remote="true"
                      data-method="put"
                      rel="nofollow"
                      href=url_for(namespace_webhook_delivery_path(@namespace, @webhook, delivery))
                      ]
                        i.fa.fa-refresh.fa-lg
                  - else
                    a.btn.btn-default.btn-retrigger-webhook[data-placement="left"
                      data-toggle="popover"
                      data-title="Please confirm"
                      data-content='<p>This webhook is disabled. Are you sure you want to retrigger it?</p><a class="btn btn-primary">No</a> <a class="btn btn-default" data-method="put" rel="nofollow" data-remote="true" href="#{url_for(namespace_webhook_delivery_path(@namespace, @webhook, delivery))}">Yes</a>'
                      data-html="true"
                      tabindex="0"
                      role="button"
                      ]
                      i.fa.fa-refresh.fa-lg
  .panel-footer= paginate(@deliveries)
